<div class="full_w">
    <div class="h_title"><?php echo Yii::t('AdmincpModule.admincp', 'Update Field'); ?></div>
    <?php 
        foreach(Yii::app()->admin->getFlashes() as $key => $message){
            echo '<div class="n_'.$key.'"><p>'.$message."</p></div>\n";
        }
    ?>
    <form action="" method="post" id="frmTaxonomy">
        <div class="element">
            <label>Field name <span class="red">*</span></label>
            <input type="text" name="field_name" id="name" class="text required" value="<?php echo isset($arrItemInfo['field_name'])?$arrItemInfo['field_name']:null; ?>">
        </div>
        <div class="element">
            <label>Field code <span class="red">*</span></label>
            <input type="text" name="field_code" id="code" class="text required" value="<?php echo isset($arrItemInfo['field_code'])?$arrItemInfo['field_code']:null; ?>">
        </div>
        <div class="element">
            <label>Description</label>
            <textarea name="field_description" id="description" class="textarea"><?php echo isset($arrItemInfo['field_description'])?$arrItemInfo['field_description']:null; ?></textarea>
        </div>
        <div class="element">
            <label>Input type <span class="red">*</span></label>
            <select name="attributes[input_type]" id="input_type">
            	<option>-- Select --</option>
            	<option value="text" <?php if(isset($arrItemInfo['field_attributes']['input_type']) && $arrItemInfo['field_attributes']['input_type'] == 'text'): ?>selected<?php endif; ?>>Text</option>
                <option value="password" <?php if(isset($arrItemInfo['field_attributes']['input_type']) && $arrItemInfo['field_attributes']['input_type'] == 'password'): ?>selected<?php endif; ?>>Password</option>
                <option value="radio" <?php if(isset($arrItemInfo['field_attributes']['input_type']) && $arrItemInfo['field_attributes']['input_type'] == 'radio'): ?>selected<?php endif; ?>>Radio</option>
                <option value="checkbox" <?php if(isset($arrItemInfo['field_attributes']['input_type']) && $arrItemInfo['field_attributes']['input_type'] == 'checkbox'): ?>selected<?php endif; ?>>Checkbox</option>
                <option value="textarea" <?php if(isset($arrItemInfo['field_attributes']['input_type']) && $arrItemInfo['field_attributes']['input_type'] == 'textarea'): ?>selected<?php endif; ?>>Textarea</option>
                <option value="file" <?php if(isset($arrItemInfo['field_attributes']['input_type']) && $arrItemInfo['field_attributes']['input_type'] == 'file'): ?>selected<?php endif; ?>>File</option>
                <option value="select" <?php if(isset($arrItemInfo['field_attributes']['input_type']) && $arrItemInfo['field_attributes']['input_type'] == 'select'): ?>selected<?php endif; ?>>Select</option>
            </select>
            <p class="description">Display the type of input field such as text, textarea, select (combobox), checkbox, radio...</p>
        </div>
         <div class="element">
            <label>Data type <span class="red">*</span></label>
            <select name="attributes[data_type]" id="data_type">
                <option value="string" <?php if(isset($arrItemInfo['field_attributes']['data_type']) && $arrItemInfo['field_attributes']['data_type'] == 'string'): ?>selected<?php endif; ?>>String</option>
            	<option value="number" <?php if(isset($arrItemInfo['field_attributes']['data_type']) && $arrItemInfo['field_attributes']['data_type'] == 'number'): ?>selected<?php endif; ?>>Number</option>
            </select>
            <p class="description">The data type of this field such as integer, string, decimal, boolean... It will be helpful to check if the data inputed correctly</p>
        </div>
        <div class="element">
            <label>Max-length <span class="red">*</span></label>
            <input type="text" name="attributes[maxlength]" id="maxlength" value="<?php echo isset($arrItemInfo['field_attributes']['maxlength'])?$arrItemInfo['field_attributes']['maxlength']:null; ?>">
            <p class="description">Max-length of this field, it will be helpful to limit the length of data inputed, [0] or [null] means unlimited</p>
        </div>
         <div class="element">
            <label>Allow null value <span class="red">*</span></label>
            <input type="radio" name="attributes[required]" id="required-yes" value="1" <?php if(isset($arrItemInfo['field_attributes']['required']) && $arrItemInfo['field_attributes']['required'] == '1'): ?>checked><?php endif; ?> <label for="required-yes" style="display:inline; font-weight:normal;">Yes </label> - 
            <input type="radio" name="attributes[required]" id="required-no" value="0" <?php if(isset($arrItemInfo['field_attributes']['required']) && $arrItemInfo['field_attributes']['required'] == '0'): ?>checked<?php endif; ?>> <label for="required-no" style="display:inline; font-weight:normal;">No </label>
        	<p class="description">Specifies if this input field must be filled out before before submitting</p>
        </div>
         <div class="element">
            <label>Default value <span class="red">*</span></label>
            <input type="text" name="attributes[value]" id="value" value="<?php echo isset($arrItemInfo['field_attributes']['value'])?$arrItemInfo['field_attributes']['value']:null; ?>">
            <p class="description">Specifies the default value of field (selected or checked). Null value if leave it blank</p>
        </div>
        <div class="element">
            <label>Style</label>
            <textarea name="attributes[style]" id="style" class="textarea"><?php echo isset($arrItemInfo['field_attributes']['style'])?$arrItemInfo['field_attributes']['style']:null; ?></textarea>
            <p class="description">Specifies an inline style (css) for field, separated by semicolon</p>
        </div>
        <div class="element">
            <label>Class</label>
            <textarea name="attributes[class]" id="class" class="textarea"><?php echo isset($arrItemInfo['field_attributes']['class'])?$arrItemInfo['field_attributes']['class']:null; ?></textarea>
            <p class="description">The class attribute in an HTML Input element, separated by a space</p>
        </div>
        <div class="element">
            <label>Predefined Data</label>
            <div id="field_options">
            <?php if(empty($arrItemInfo['field_id']) || empty($arrItemInfo['field_attributes']['options'])): ?>
                <div><input type="text" name="attributes[options][value][]" placeholder="value"> => <input type="text" name="attributes[options][title][]" placeholder="title"> <a href="javascript:void(0);" onClick="javascript:addOption();">Add option</a></div>
                <div><input type="text" name="attributes[options][value][]" placeholder="value"> => <input type="text" name="attributes[options][title][]" placeholder="title"></div>			
            <?php else: ?>
                <?php foreach($arrItemInfo['field_attributes']['options']['value'] as $key=>$R): ?>
                <div><input type="text" name="attributes[options][value][]" placeholder="value" value="<?php echo isset($arrItemInfo['field_attributes']['options']['value'][$key])?$arrItemInfo['field_attributes']['options']['value'][$key]:''; ?>"> => <input type="text" name="attributes[options][title][]" placeholder="title" value="<?php echo isset($arrItemInfo['field_attributes']['options']['title'][$key])?$arrItemInfo['field_attributes']['options']['title'][$key]:''; ?>"> 
					<?php if($key == 0): ?>
                    	<a href="javascript:void(0);" onClick="javascript:addOption();">Add option</a>
                    <?php elseif($key >= 2): ?>
                    	<a href="javascript:void(0);" onClick="removeOption(this)">Remove</a>
                    <?php endif; ?>
                </div>
            	<?php endforeach; ?>
			<?php endif; ?>
            </div>
            <p class="description">The predefined data of this field, such as a list of items for selection</p>
        </div>
        <div class="entry">
            <input type="hidden" name="id" id="id" value="<?php echo isset($arrItemInfo['field_id'])?$arrItemInfo['field_id']:null; ?>">
            <input type="hidden" name="taxonomy" id="taxonomy" value="<?php echo isset($arrItemInfo['taxonomy_id'])?$arrItemInfo['taxonomy_id']:null; ?>">
            <button type="submit">Submit</button> <button>Cancel</button>
        </div>
    </form>
</div>
<script type="text/javascript">
	function addOption(){
		$('#field_options').append(
			'<div><input type="text" name="attributes[options][value][]" placeholder="value"> => <input type="text" name="attributes[options][title][]" placeholder="title"> <a href="javascript:void(0);" onClick="removeOption(this)">Remove</a></div>'
		)
	}
	function removeOption(obj){
		$(obj).parent().remove();	
	}
	$(function(){
		$('#frmTaxonomy').validate();		
	});
</script>